package cn.elwy.upms.shiro.check;

import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.elwy.common.entity.Parameter;
import cn.elwy.common.entity.ResultDto;
import cn.elwy.framework.context.SpringContext;
import cn.elwy.upms.entity.User;
import cn.elwy.upms.service.UserService;

@Service
@DependsOn("springContext")
@Transactional(readOnly = true)
public class ShiroFactroy implements IShiro {

	public static IShiro instance() {
		return SpringContext.getBean(IShiro.class);
	}

	@Override
	public User user(String username) {
		UserService userService = SpringContext.getBean(UserService.class);
		Parameter parameter = new Parameter();
		parameter.setId("11");
		parameter.addParam("USER_NAME_", username);
		// parameter.addParam("FPASSWORD", password);
		final ResultDto rd = userService.queryByCondition(parameter);// PrimaryKey(parameter.getId());
		if (rd != null) {
			User user = (User) rd.getDatas().get(0);
//			Session session = SecurityUtils.getSubject().getSession();
//			session.setAttribute("user", user);
			// 设置盐值
			return user;
		}
		return null;
	}

}
